package cn.com.dao.imp;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import cn.com.dao.baseDao;

public class baseDaoImp implements baseDao {

	public Connection getCon() {
		Connection conn=null;
		try {
			conn=this.mysqlCon();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}
	
	public Connection oracleCon() throws Exception{
		Connection conn=null;
		Class.forName("oracle.jdbc.driver.OracleDriver");
		String url = "jdbc:oracle:thin:@localhost:1521:orcl";
		conn = DriverManager.getConnection(url, "twtiyb", "twtiyb");
		return conn;
	}
	
	public Connection mysqlCon() throws Exception{
	   //容易犯的错误
	   //    一是：连接URL格式出现了问题(Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/XX","root","XXXX")
	   // 二是：驱动字符串出错(com.mysql.jdbc.Driver)
	   // 三是Classpath中没有加入合适的mysql_jdbc驱动
		Connection conn=null;
		Class.forName("com.mysql.jdbc.Driver");
		String url = "jdbc:mysql://localhost:3306/test";
		conn = DriverManager.getConnection(url, "root", "123123");
		return conn;
	}
	
	public Object get(String sql){
		ResultSet rs  = null;
		try {
			Connection conn = this.getCon();
			Statement stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
		} catch (Exception e) {
		}		
		return rs;
	}
}
